**********************
*** PANELS A, B, D ***
**********************
clear all 
set more off
cd "/Users/yasenov/Dropbox/mariel_boatlift/jhr_version/jhr_figures"
global folder /Users/yasenov/Dropbox/mariel_boatlift/revision_version/revision_data/
set scheme s1color

use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 

keep if smsa == 9 | smsarank == 33 | smsa == 32 | smsa == 1 | smsa == 26
tab smsa

collapse (mean) logearnwke loguearnhre unemp [pw=earnwt], by(year smsarank)
merge 1:1 year smsa using $folder/msa_controls_may-org.dta, nogenerate keep(3)
xtset smsa year

local controls low_skilled hisp manuf
synth logearnwke `controls', trunit(26) trperiod(1980) nested keep(fig5a.dta, replace)

local controls low_skilled hisp manuf
synth loguearnhre `controls', trunit(26) trperiod(1980) nested keep(fig5b.dta, replace)

local controls low_skilled hisp manuf
synth unemp `controls', trunit(26) trperiod(1980) nested keep(fig5d.dta, replace)

use fig5a, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
scalar a = (synthetic[7]-miami[7])/1.8
replace synthetic = synthetic - a
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami")) ///
	t2title("Log Weekly Wages") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	yscale(range(4.8 5.3)) ///
	ylabel(4.8(.1)5.3) ///
	text(5.3 1990.8 "Panel A")  plotregion(lwidth(none)) nodraw

graph copy one, replace

use fig5b, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
scalar b = (synthetic[7]-miami[7])/1.8
replace synthetic = synthetic - b
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami") size(small)) ///
	t2title("Log Hourly Wages") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	text(1.7 1990.8 "Panel B") ///
	yscale(range(1.2 1.7)) ///
	ylabel(1.2(.1)1.7) plotregion(lwidth(none)) nodraw
	
graph copy two, replace

use fig5d, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami") size(small)) ///
	t2title("Unemployment") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	text(.25 1990.8 "Panel D") ///
	plotregion(lwidth(none)) nodraw

graph copy four, replace
	
****************
*** PANEL C ****
****************
clear 
use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 

keep if smsa == 9 | smsarank == 33 | smsa == 32 | smsa == 1 | smsa == 26

collapse (p15) p15logearnwke=logearnwke (mean) unemp [pw=earnwt], by(year smsarank)
merge 1:1 year smsa using $folder/msa_controls_may-org.dta, nogenerate keep(3)
xtset smsa year  

local controls low_skilled hisp manuf
synth p15logearnwke `controls', trunit(26) trperiod(1980) nested keep(fig5c.dta, replace)

use fig5c, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami")) ///
	t2title("15th Percentile Log Weekly Wages") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	text(5.1 1990.8 "Panel C") ///
	yscale(range(4.6 5.1)) ///
	ylabel(4.6(.1)5.1) ///
	plotregion(lwidth(none)) nodraw

graph copy three, replace

grc1leg one two three four,	imargin(vsmall) legendfrom(four)
graph export "jhr_fig5.pdf", replace
